package pers.luchuan.provider.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("provider")
public class ProviderController {
    @Value("${server.port}")
    private String port;
    @Value("${spring.cloud.client.ip-address}")
    private String ip;
    @GetMapping("{id}")
    public String test(@PathVariable Long id) {
        if (id == 1) {
            throw new RuntimeException("服务异常"); // 模拟后端服务异常
        }
        try {
            Thread.sleep(2000); // 模拟后端响应数据时间
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "service from " + ip + ":" + port;
    }
}
